{% include 'QLGL/QLGL_index.html' %}

<div class="am-cf admin-main">
  {% include 'sidebar.html' %}
  <!-- content start -->
  <div class="admin-content">
    <div class="admin-content-body">
      <div class="am-cf am-padding">
        <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">桥梁数据</strong></div>
      </div>
      <div class="am-g" style="position: absolute;height: 100%;right: 0px;left: 260px;width: auto;">

        {% include 'QLGL/QLSJ/QLGL_QLSJ_SIDEBAR.html' %}

        <div class="am-u-sm-10" style="position: absolute;width:auto;right:0;left: 200px;height:85%;overflow-y: scroll;">
          <div class="am-u-sm-12 am-u-md-6">
            <div class="am-btn-toolbar">
              <div class="am-btn-group am-btn-group-xs">
                <button style="margin: 0 5px" type="button" class="am-btn am-btn-default am-btn-xs am-text-secondary" onclick="back_to()">返回</button>
              </div>
            </div>
          </div>

          <table id="grid" class="am-table am-table-striped am-table-hover table-main am-table-compact am-text-nowrap">
            <thead>
              <tr>
                <th class="table-title">评价部件</th>
                <th class="table-title">默认权重</th>
                <th class="table-title">自定义权重</th>
                <th class="table-title">操作</th>
              </tr>
            </thead>
            <tbody>
              <tr class="odd">
                <td colspan="4"><strong>上部结构</strong></td>
              </tr>
              <!-- <a href="">{{ datalist }}</a> -->
              {% for i in datalist %}
              {% if i.position_code == 0 %}
              {% if i.status == 0 %}
              <tr>
                <td class="blue"> {{ i.component_name }} </td>
                <td class="blue"> {{ i.default_weight }} </td>
                <td class="blue"></td>
                <td class="blue"></td>
              </tr>
              
              {% elif i.status == 1 %}
              <tr class="odd">
                <td> {{ i.component_name }} </td>
                <td> {{ i.default_weight }} </td>
                <td> <input type="text" id="weight_{{ i.parts_code }}"  value="{{ i.weight }}" onblur="if(! /^0.[0-9]{1,3}|1$/.test(this.value)){alert('只能填写不大于1的三位小数！');this.value='';}"> <input type="hidden" class="weights_{{ i.position_code }}" attr1={{ i.parts_code }}  value="{{ i.weight }}" > </td>
                <td><div class="am-btn-toolbar"><div class="am-btn-group am-btn-group-xs"><button class="am-btn am-btn-default am-btn-xs am-text-secondary" onclick="choose_component({{ i.bridge_id }},{{ i.unit_id }},{{ i.parts_code }},{{ i.unit_component_id }})">选择构件</button><button class="am-btn am-btn-default am-btn-xs am-text-secondary" onclick="see_component({{ i.bridge_id }},{{ i.unit_id }},{{ i.parts_code }},{{ i.unit_component_id }})">查看已选构件</button><button class="am-btn am-btn-default am-btn-xs am-text-secondary" onclick="save({{ i.bridge_id }},{{ i.unit_id }},{{ i.parts_code }},'{{ i.component_name }}',{{ i.position_code }},{{ i.default_weight }})">保存权重</button><button class="am-btn am-btn-default am-btn-xs am-text-secondary am-disabled"  onclick="delect('{{ i.component_name }}',{{ i.unit_id }})">删除</button></div></div></td>
              </tr>
              
              {% endif %}
              {% endif %}
              {% endfor %}
              <tr class="odd">
                <td colspan="4"><strong>下部结构</strong></td>
              </tr>
              {% for i in datalist %}
              {% if i.position_code == 1 %}
              {% if i.status == 0 %}
              <tr>
                <td class="blue"> {{ i.component_name }} </td>
                <td class="blue"> {{ i.default_weight }} </td>
                <td class="blue"></td>
                <td class="blue"></td>
              </tr>
              
              {% elif i.status == 1 %}
              <tr class="odd">
                <td> {{ i.component_name }} </td>
                <td> {{ i.default_weight }} </td>
                <td> <input type="text" id="weight_{{ i.parts_code }}"  value="{{ i.weight }}" onblur="if(! /^0.[0-9]{1,3}|1$/.test(this.value)){alert('只能填写不大于1的三位小数！');this.value='';}"> <input type="hidden" class="weights_{{ i.position_code }}" attr1={{ i.parts_code }}  value="{{ i.weight }}" > </td>
                <td><div class="am-btn-toolbar"><div class="am-btn-group am-btn-group-xs"><button class="am-btn am-btn-default am-btn-xs am-text-secondary" onclick="choose_component({{ i.bridge_id }},{{ i.unit_id }},{{ i.parts_code }},{{ i.unit_component_id }})">选择构件</button><button class="am-btn am-btn-default am-btn-xs am-text-secondary" onclick="see_component({{ i.bridge_id }},{{ i.unit_id }},{{ i.parts_code }},{{ i.unit_component_id }})">查看已选构件</button><button class="am-btn am-btn-default am-btn-xs am-text-secondary" onclick="save({{ i.bridge_id }},{{ i.unit_id }},{{ i.parts_code }},'{{ i.component_name }}',{{ i.position_code }},{{ i.default_weight }})">保存权重</button><button class="am-btn am-btn-default am-btn-xs am-text-secondary" disabled="disabled" onclick="delect('{{ i.component_name }}',{{ i.unit_id }})">删除</button></div></div></td>
              </tr>
              
              {% endif %}
              {% endif %}
              {% endfor %}
              <tr class="odd">
                <td colspan="4"><strong>桥面系</strong></td>
              </tr>
              {% for i in datalist %}
              {% if i.position_code == 2 %}
              {% if i.status == 0 %}
              <tr >
                <td class="blue"> {{ i.component_name }} </td>
                <td class="blue"> {{ i.default_weight }} </td>
                <td class="blue"></td>
                <td class="blue"></td>
              </tr>
              
              {% elif i.status == 1 %}
              <tr class="odd">
                <td> {{ i.component_name }} </td>
                <td> {{ i.default_weight }} </td>
                <td> <input type="text"  id="weight_{{ i.parts_code }}"  value="{{ i.weight }}" onblur="if(! /^0.[0-9]{1,3}|1$/.test(this.value)){alert('只能填写不大于1的三位小数！');this.value='';}"> <input type="hidden" class="weights_{{ i.position_code }}" attr1={{ i.parts_code }}  value="{{ i.weight }}" >  </td>
                <td><div class="am-btn-toolbar"><div class="am-btn-group am-btn-group-xs"><button class="am-btn am-btn-default am-btn-xs am-text-secondary" onclick="choose_component({{ i.bridge_id }},{{ i.unit_id }},{{ i.parts_code }},{{ i.unit_component_id }})">选择构件</button><button class="am-btn am-btn-default am-btn-xs am-text-secondary" onclick="see_component({{ i.bridge_id }},{{ i.unit_id }},{{ i.parts_code }},{{ i.unit_component_id }})">查看已选构件</button><button class="am-btn am-btn-default am-btn-xs am-text-secondary" onclick="save({{ i.bridge_id }},{{ i.unit_id }},{{ i.parts_code }},'{{ i.component_name }}',{{ i.position_code }},{{ i.default_weight }})">保存权重</button><button class="am-btn am-btn-default am-btn-xs am-text-secondary " disabled="disabled" onclick=delect('{{ i.component_name }}',{{ i.unit_id }})>删除</button></div></div></td>
              </tr>
              
              {% endif %}
              {% endif %}
              {% endfor %}
            

            </tbody>
          </table>
        </div>
      </div>
    </div>
  </div>
</div>
{% include 'footer.html' %}
<!--[if lt IE 9]>
<script src="http://libs.baidu.com/jquery/1.11.1/jquery.min.js"></script>
<script src="http://cdn.staticfile.org/modernizr/2.8.3/modernizr.js"></script>
<script src="assets/js/amazeui.ie8polyfill.min.js"></script>
<![endif]-->

<!--[if (gte IE 9)|!(IE)]><!-->
<script src="/static/assets/js/jquery.min.js"></script>
<!--<![endif]-->
<script src="/static/assets/js/amazeui.min.js"></script>
<script src="/static/assets/js/amazeui.tree.js"></script>
<script type="text/javascript" src="/static/assets/js/layer.js"></script>
<script src="/static/assets/datatables/amazeui.datatables.min.js"></script>
<script src="/static/assets/dialog/amazeui.dialog.min.js"></script>
<link rel="stylesheet" type="text/css" href="/static/assets/css/amazeui.tree.css" />
<script src="/static/assets/js/app.js"></script>
<script src="/static/assets/js/util.js"></script>

<style type="text/css">
  .blue{
    background-color:#87CEEB !important;
  }
  .li_a {
    color: #5c5c5c;
  }
</style>
<script type="text/javascript">
  $("#collapse-nav1").addClass("am-in");
  $("#qlgl").removeClass("am-collapsed");
  $("#qlglOqlsj").css("color", "#3399CC");
  $("#qlgl").css("color", "#3399CC");
  $("#qlsjOqllb").removeClass("li_a");
    
  function choose_component(bridge_id,unit_id,parts_code,unit_component_id){
    popup("选择构件", "/QLXJ_QLLB_PFDY_SelectComponent/?bridge_id="+bridge_id+"&unit_id="+unit_id+"&parts_code="+parts_code+"&unit_component_id="+unit_component_id+"")
  }

  function see_component(bridge_id,unit_id,parts_code,unit_component_id){
    popup("查看已选构件", "/QLXJ_QLLB_PFDY_SelectedComponent_index/?bridge_id="+bridge_id+"&unit_id="+unit_id+"&parts_code="+parts_code+"&unit_component_id="+unit_component_id+"")
  }

  function save(bridge_id,unit_id,parts_code,component_name,position_code,default_weight) {
      if (!validNum(position_code,parts_code))
      {
          AlertMSG("自定义权重和不得大于1,请重新填写");
          return;
      }

    var weight = $("#weight_"+parts_code+"").val();
    $.ajax({
          "url": "/QLXJ_QLLB_PFDY_weight/?unit_id=" + unit_id + "&bridge_id=" + bridge_id + "&parts_code=" + parts_code + "&component_name=" + component_name + "&position_code=" + position_code + "&default_weight=" + default_weight + "&weight=" + weight + "",
          "datatype": "json",
          "type": "get",
          "async": "false"
        }).success(function(data) {
          if(data.status == 1) {
            window.location.reload();
            message_layer(data.message)
          } else {
            AlertMSG(data.message)
          }
        }).error(function(data) {
          AlertMSG("保存失败！")
        });
  }
// 验证所有权重和不得大于1
var validNum = function(position_code,parts_code){
    var weight = $(".weights_"+position_code+"");
    var totalNum = 0;
    weight.each(function(x,y){
      // console.log("aaa"+$(y).val())
      if(parseInt($(y).attr("attr1")) == parseInt(parts_code)){
        totalNum = PublicUtil.numAdd(totalNum,$("#weight_"+parts_code+"").val()*1);
        // console.log(111+totalNum)
      }else{
        totalNum = PublicUtil.numAdd(totalNum,$(y).val()*1);
        // console.log(222+totalNum)
      }
    });
    // console.log(totalNum)
    return totalNum<=1.0;
}

  function delect(component_name, unit_id) {
    AMUI.dialog.confirm({
      title: '删除确认',
      content: '您确认删除评分单元[' + component_name + ']?',
      onConfirm: function() {
        //console.log('onConfirm,save ' + organize_id);
        $.ajax({
          "url": "/QLXJ_QLLB_PFDY_del/?unit_id=" + unit_id + "",
          "datatype": "json",
          "type": "get",
          "async": "false"
        }).success(function(data) {
          if(data.status == 1) {
            window.location.reload();
            message_layer(data.message)
          } else {
            AlertMSG(data.message)
          }
        }).error(function(data) {
          AlertMSG("删除失败！")
        });
      },
      onCancel: function() {
        console.log('onCancel')
      }
    });
  };

  function popup(title, url) {
    var index = layer.open({
      type: 2,
      title: title,
      content: url,
      area: ['900px', '560px'],

    });
    // layer.full(index);
  }
  var AlertMSG = function(msg) {
    AMUI.dialog.alert({
      title: '错误提示',
      content: msg,
      onConfirm: function() {
        console.log('close');
      }
    });
  }
  function back_to() {
    window.history.back(-1);
  }


  function message_layer(message){
    layer.msg(message, {
    time: 2000 //2秒关闭（如果不配置，默认是3秒）
  }); 
}

</script>

</body>

</html>